package utils

import (
	"gitee.com/ymofen/gobase"
	"gitee.com/ymofen/gobase/factory"
	"gitee.com/ymofen/gobase/subpub"
)

type Subscribe = subpub.Subscribe
type ISub = subpub.ISub
type IUnsub = subpub.IUnsub
type IPub = subpub.IPub
type SubFunc = subpub.SubFunc

var NewSubscribe = subpub.NewSubscribe

//func NewSubscribe() *Subscribe {
//	return gobase.NewSubscribe()
//}

type t_createfun func(args ...interface{}) (rval interface{}, err error)

// 接口, 对象都创建完后
type I_initializer interface {
	DoInitialize()
}

var RegisterCreate = factory.RegisterCreateFunc
var UnregisterCreate = factory.UnregisterCreateFunc
var CreateInstance = factory.CreateInstance
var GetBean = factory.GetVar
var RegisterBean = factory.RegisterVar
var RemoveBean = factory.RemoveVar
var RangeBeans = factory.RangeVarList

func RangeBeans_DoInitialize() {
	RangeBeans(func(val interface{}) bool {
		if intf, ok := val.(I_initializer); ok {
			intf.DoInitialize()
		}
		return true
	})
}

type StrMap = gobase.StrMap

var NewStrMap0 = gobase.NewStrMap
var NewStrMapEx = gobase.NewStrMapEx
var MapEncode = gobase.MapEncode

func NewStrMap(s, itmsep string) StrMap {
	r := make(StrMap)
	r.ParseKVPairs(s, "=", itmsep)
	return r
}
